﻿using Ionic.Zip;
using System;
using System.IO;
using System.Linq;
using System.Text;

namespace Xpom_Xpum__Browser_Integrator.Subsystems
{
    internal class ZipManager
    {
        internal void PackDirectoryToZIP(string directoryPath)
        {
            PackDirectoryToZIP(directoryPath,
                Directory.GetParent(directoryPath).FullName + ".zip");
        }

        internal void PackDirectoryToZIP(string directoryPath, string zipFilePath)
        {
            Console.WriteLine("Processing: ");
            Console.WriteLine("Packing To ZIP...");

            try
            {
                using (ZipFile zipFile = new ZipFile())
                {
                    zipFile.AlternateEncoding = Encoding.UTF8;
                    zipFile.AlternateEncodingUsage = ZipOption.AsNecessary;
                    zipFile.AddDirectory(directoryPath, Path.GetFileName(Directory.GetParent(directoryPath).FullName));
                    zipFile.Save(zipFilePath);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error!");
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                Console.ReadKey();
            }

            Console.WriteLine("Done!");
        }
    }
}
